/*
* Sun Public License Notice
*
* The contents of this file are subject to the Sun Public License
* Version 1.0 (the "License"). You may not use this file except in
* compliance with the License. A copy of the License is available at
* http://www.sun.com/
*
* The Original Code is Forte for Java, Community Edition. The Initial
* Developer of the Original Code is Sun Microsystems, Inc. Portions
* Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
*/
package org.netbeans.modules.autoupdate;
import java.io.File;
import java.io.FileFilter;
import java.awt.Dialog;
import java.util.ResourceBundle;
import java.text.MessageFormat;
import javax.swing.JFileChooser;
import javax.swing.DefaultListModel;
import org.openide.DialogDescriptor;
import org.openide.NotifyDescriptor;
import org.openide.TopManager;
import org.openide.util.NbBundle;
import org.openide.util.HelpCtx;
import org.openide.util.RequestProcessor;
/** Lets the user select module/path/IDE distribution files to install
* @author Petr Hrebejk
*/
public class SelectModulesPanel extends javax.swing.JPanel {
private static final String EMPTY_STRING = ""; // NOI18N
private static final javax.swing.filechooser.FileFilter NBM_FILE_FILTER = new NbmFileFilter();
/** The list model */
private DefaultListModel modulesModel;
/** The ResourceBundle */
private static final ResourceBundle bundle = NbBundle.getBundle( DownloadProgressPanel.class );
/** Stores the last selected directory */
File defaultDir = null;
private Wizard.Validator validator;
static final long serialVersionUID =8279789280479374665L;
/** Creates new form CheckProgressPanel */
public SelectModulesPanel( Wizard.Validator validator) {
initComponents ();
this.validator = validator;
((javax.swing.border.TitledBorder) modulePanel.getBorder() ).setTitle(
bundle.getString( "SelectModulesPanel.panel.border" ) );
reset();
}
/** Overload getPreffered size to get a bit bigger dialog */
public java.awt.Dimension getPreferredSize() {
return new java.awt.Dimension( 350, super.getPreferredSize().height );
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the FormEditor.
*/
private void initComponents () {//GEN-BEGIN:initComponents
jTextArea1 = new javax.swing.JTextArea ();
modulePanel = new javax.swing.JPanel ();
jScrollPane1 = new javax.swing.JScrollPane ();
modulesList = new javax.swing.JList ();
addButton = new javax.swing.JButton ();
setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints1;
setBorder (new javax.swing.border.EmptyBorder(new java.awt.Insets(16, 8, 16, 8)));
jTextArea1.setLineWrap (true);
jTextArea1.setWrapStyleWord (true);
jTextArea1.setBackground ((java.awt.Color) javax.swing.UIManager.getDefaults ().get ("Label.background")); // NOI18N
jTextArea1.setText (org.openide.util.NbBundle.getBundle(SelectModulesPanel.class).getString("SelectModulesPanel.jTextArea1.text"));
jTextArea1.setEditable (false);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints1.insets = new java.awt.Insets (32, 0, 24, 0);
gridBagConstraints1.anchor = java.awt.GridBagConstraints.NORTH;
gridBagConstraints1.weightx = 1.0;
add (jTextArea1, gridBagConstraints1);
modulePanel.setLayout (new java.awt.GridBagLayout ());
java.awt.GridBagConstraints gridBagConstraints2;
modulePanel.setBorder (new javax.swing.border.TitledBorder("title")); // NOI18N
jScrollPane1.setViewportView (modulesList);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridheight = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints2.insets = new java.awt.Insets (0, 5, 5, 5);
gridBagConstraints2.weightx = 1.0;
gridBagConstraints2.weighty = 1.0;
modulePanel.add (jScrollPane1, gridBagConstraints2);
addButton.setText (org.openide.util.NbBundle.getBundle(SelectModulesPanel.class).getString("SelectModulesPanel.addButton.text"));
addButton.addActionListener (new java.awt.event.ActionListener () {
public void actionPerformed (java.awt.event.ActionEvent evt) {
addButtonActionPerformed (evt);
}
}
);
gridBagConstraints2 = new java.awt.GridBagConstraints ();
gridBagConstraints2.gridx = 1;
gridBagConstraints2.gridy = 0;
gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL;
gridBagConstraints2.insets = new java.awt.Insets (0, 2, 5, 5);
gridBagConstraints2.anchor = java.awt.GridBagConstraints.SOUTHEAST;
gridBagConstraints2.weighty = 1.0;
modulePanel.add (addButton, gridBagConstraints2);
gridBagConstraints1 = new java.awt.GridBagConstraints ();
gridBagConstraints1.gridwidth = 0;
gridBagConstraints1.gridheight = 0;
gridBagConstraints1.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints1.weightx = 1.0;
gridBagConstraints1.weighty = 1.0;
add (modulePanel, gridBagConstraints1);
}//GEN-END:initComponents
private void addButtonActionPerformed (java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode( JFileChooser.FILES_AND_DIRECTORIES );
chooser.addChoosableFileFilter( NBM_FILE_FILTER );
chooser.setFileFilter(NBM_FILE_FILTER);
chooser.setDialogTitle(bundle.getString("CTL_FileChooser_Title"));
if ( defaultDir != null) {
chooser.setCurrentDirectory( defaultDir );
}
if (chooser.showDialog(TopManager.getDefault ().getWindowManager ().getMainWindow (),
bundle.getString("CTL_FileChooser_Approve_Button"))
== JFileChooser.APPROVE_OPTION) {
File dir = chooser.getSelectedFile();
File[] files = null;
if ( dir.isDirectory() ) {
files = dir.listFiles( new FileFilter() {
public boolean accept( File file ) {
if ( !file.isDirectory() && file.getName().toUpperCase().endsWith(".NBM") ) // NOI18N
return true;
else
return false;
}
} );
}
else {
files = new File[] { dir };
}
for ( int i = 0; i < files.length; i++ ) {
if ( i == 0 )
validator.setValid( true );
if ( !selectedFile( files[i] ) ) {
modulesModel.addElement(files[i]);
}
}
}
defaultDir = chooser.getCurrentDirectory();
}//GEN-LAST:event_addButtonActionPerformed
private boolean selectedFile( File file ) {
for ( int i = 0; i < modulesModel.size(); i++ ) {
if ( ((File)modulesModel.elementAt(i)).compareTo( file ) == 0 )
return true;
}
return false;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JTextArea jTextArea1;
private javax.swing.JPanel modulePanel;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JList modulesList;
private javax.swing.JButton addButton;
// End of variables declaration//GEN-END:variables
File[] getFiles() {
File[] files = new File[ modulesModel.size() ];
for ( int i = 0; i < modulesModel.size(); i ++ ) {
files[i] = (File)modulesModel.elementAt( i );
}
return files;
}
/** Clears all modules in listbox, ceates new model,
* if the model does not exist yet
*/
void reset() {
if ( modulesModel == null ) {
modulesModel = new DefaultListModel();
modulesList.setModel( modulesModel );
}
else {
modulesModel.removeAllElements();
}
}
private static class NbmFileFilter extends javax.swing.filechooser.FileFilter {
public boolean accept( File f ) {
return f.getName().toLowerCase().endsWith( ".nbm" ) || f.isDirectory(); // NOI18N
}
public String getDescription() {
return bundle.getString( "CTL_FileFilterDescription" );
}
}
}
/*
* Log
* 6 Gandalf-post-FCS1.4.1.0 3/30/00 Jaroslav Tulach L10N fix of 5814
* 5 Gandalf 1.4 1/12/00 Petr Hrebejk i18n
* 4 Gandalf 1.3 11/27/99 Patrik Knakal
* 3 Gandalf 1.2 11/12/99 Petr Hrebejk Bug fixes: Texts, Not
* NetBeans patches, unselecting modules
* 2 Gandalf 1.1 11/9/99 Petr Hrebejk Better selection of nbm
* files
* 1 Gandalf 1.0 11/8/99 Petr Hrebejk
* $
*/